let backUrl = encodeURIComponent(window.location.href);
const jumpHref = {

    // TODO: 跳到登录地址 TODO:
    login: () => {
        return `/appidx/login?authUrl=${backUrl}`
    },
    // 协作组相关地址
    group: {
        create: (authUrl) => {
            // let backUrl = encodeURIComponent(window.location.href);
            return '/group/edit';
        },
        detail: (groupId, authUrl) => {
            // let backUrl = encodeURIComponent(window.location.href);
            return `/group/${groupId}/detail`;
        }
    },

    // 资源相关地址
    resource: {
        detail: (sourceId, resourceFrom = '') => {
            return `/resource/detail?sourceId=${sourceId}&resourceFrom=${resourceFrom}`
        }
    },

    // 活动
    activity: {
        detail: (activityId) => {
            return `/ac2/activity/${activityId}/detail`
        },
        create: () => {
            return '/ac2/activity/0/edit?bizType=xicheng';
        }
    },

    // 管理中心
    idxmc: {
        index: () => {
            return '/idxmc/home';
        }
    },
    // 视频案例
    videocase: {
        create: () => {
            return '/eoc/createCase?from=square';
        },
        edit: (moocId) => {
            return `/eoc/editCase?moocId=${moocId}&from=square`;
        },
        detail: (moocId) => {
            return `/eoc/case/detail/${moocId}`;
        }
    },
    // 听评课
    lesson: {
        create: () => {
            return '/eoc/createCourse?from=square';
        },
        detail: (moocId) => {
            return `/eoc/detail/${moocId}`;
        }
    }
}

const getUrl = (keys, obj = jumpHref) => {
    let keySpre = keys.constructor == Array ? keys : keys.split('.');
    if (!obj[keySpre[0]]) {
        return false;
    }
    if (keySpre.length == 1 && obj[keySpre[0]]) {
        if (typeof obj[keySpre[0]] == 'string') {
            return obj[keySpre[0]];
        }
        return obj[keySpre[0]]();
    }
    let state = getUrl(keySpre.splice(1), obj[keySpre[0]]);
    return state;
}

export {
    jumpHref
};

export {
    getUrl
}
